package cm.tl.pms.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 全局线程池（ThreadPoolTaskExecutor）
 *
 * @author w7h1te_ywq
 * @version 1.0.0
 * @date 2024-12-05 17:38
 */
@Configuration
public class FileAsyncConfig {

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置核心线程池大小
        executor.setCorePoolSize(5);
        // 设置最大线程池大小
        executor.setMaxPoolSize(10);
        // 设置队列容量
        executor.setQueueCapacity(50);
        // 设置线程池前缀，方便排查日志
        executor.setThreadNamePrefix("deal-file-async-task-");
        // 初始化线程池
        executor.initialize();
        return executor;
    }

}
